package com.database.mapper;

import com.database.character.Post;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PostMapper {

  //查询所有帖子
  @Select("select * from post")
  List<Post> list();

  //查询特定用户发布的帖子
  @Select("select * from post where user_id = #{userId}")
  List<Post> getPostByUid(Integer userId);

  //查询特定用户收藏的帖子
  @Select("select * from post join collect on post.post_id = collect.post_id where collect.user_id = #{userId}")
  List<Post> getCollectByUid(Integer userId);

  //新增帖子
  @Insert("insert into post(content, create_time, update_time, user_id, collect_num, praise_num, comment_num)" +
    " values (#{content}, #{createTime}, #{updateTime}, #{userId}, #{collectNum}, #{praiseNum}, #{commentNum})")
  int addPost(Post post);

  //删除帖子
  @Delete("delete from post where post_id = #{postId}")
  int deletePostByPid(Integer postId);

  //修改帖子
  int updatePost(Post post);

  //根据postId查找帖子
  @Select("select * from post where post_id = #{postId}")
  Post getPostByPid(Integer postId);

  //给予帖子标题的模糊搜索
  List<Post> getPostBySearch(String search);

}
